package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("归还图书！");

        System.out.println("请输入你要归还图书的名字:>");
        Scanner scanner = new Scanner(System.in);
        String returnName = scanner.nextLine();

        int currentUserSide = bookList.getUsedSize();
        for (int i = 0; i < currentUserSide; i++) {
            //BookList中books被封装后，不能直接去访问books[i]，只能在BookList中设置一个方法返回books[i]，再遍历
            Book returnBook = bookList.getPosBook(i);

            //找到书
            if(returnName.equals(returnBook.getName())){
                returnBook.setIsBorrowed(false);
                System.out.println("归还图书成功！");
                return;
            }
        }
        //遍历完没找到
        System.out.println("没有你要归还的图书！");

    }
}
